home *** CD-ROM | disk | FTP | other *** search
- #include <ICAPI.h>
-
-
- void LogoUpdate(void);
- void RecurseDirectory(short vref, long did);
- char RepairApp(short rev);
- void WriteAppPath(void);
- void WriteString(short fie, uchar *str);
- pascal Boolean AlertKludge(DialogPtr theDialog, EventRecord *theEvent, short *itemHit);
- void DecodeVirus(void);
-
-
- #define ntt 5
-
- uchar *agaxURL="\phttp://www.cse.unsw.edu.au/~s2191331/antigax/antigax.html";
-
- Handle filnh, dirnh, volnh, numh, toth;
- DialogPtr logo;
- FSSpec *lantana;
- Ptr bigstak;
- Str63 volnm;
- Str15 nums, tots;
- OSType targType[ntt]={'APPL','APPE','APPC','cdev','appe'};
- long numo, toto, upi, ufi;
- short orrez, logef;
- Boolean hit_but, check_only, lmdco;
-
- void main(void)
- {
- ModalFilterUPP alk;
- StandardFileReply rep;
- short chx;
-
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
-
- orrez=CurResFile();
- alk=NewModalFilterProc(AlertKludge);
-
- bigstak=NewPtr(32768); // we're going to tax the conventional stack enough later...
-
- //DecodeVirus();
-
- Rechoice:
-
- numo=0;
- toto=0;
- upi=0;
- ufi=0;
- hit_but=0;
- lmdco=check_only=0;
- logef=0;
-
- chx=Alert(128,alk);
- if(chx==1) ExitToShell();
- if(chx==4)
- {
- ICInstance iccy;
- long sst, snd;
-
- sst=0;
- snd=agaxURL[0];
-
- ICStart(&iccy,'Agax');
- ICFindConfigFile(iccy,0,nil);
- ICLaunchURL(iccy,nil,(char*)agaxURL+1,snd,&sst,&snd);
- ICStop(iccy);
- ExitToShell();
- }
-
- check_only=lmdco;
-
- if(chx==2)
- {
- short rrf;
-
- StandardGetFile(nil,ntt,targType,&rep);
- if(rep.sfGood)
- {
- rrf=FSpOpenResFile(&rep.sfFile,check_only?fsRdPerm:fsRdWrPerm);
- if(!rrf || rrf==-1) Alert(129,nil);
- else
- {
- lantana=&rep.sfFile;
- numo=RepairApp(rrf);
- CloseResFile(rrf);
-
- if(numo!=-1)
- {
- if(check_only)
- ParamText(numo?"\pApplication is infected":
- "\pApplication is not infected",nil,nil,nil);
- else
- ParamText(numo?"\pApplication repaired":
- "\pApplication didn't need repairing",nil,nil,nil);
-
- Alert(130,nil);
- }
- }
- }
-
- goto Rechoice;
- }
- else if(chx==3)
- {
- VCB *queze;
-
- StandardPutFile(
- check_only?"\pLog infected apps in:":"\pOptionally log repaired apps in:",
- check_only?"\pInfected app log":"\pRepaired app log",
- &rep);
- if(rep.sfGood)
- {
- if(rep.sfReplacing) FSpDelete(&rep.sfFile);
- FSpCreate(&rep.sfFile,'ttxt','TEXT',rep.sfScript);
- FSpOpenDF(&rep.sfFile,fsWrPerm,&logef);
- if(!logef || logef==-1)
- {
- SysBeep(20);
- goto Rechoice;
- }
- WriteString(logef,
- check_only?"\pInfected application list:\r":"\pRepaired application list:\r"
- );
- }
- else
- {
- if(check_only) goto Rechoice; // no pt searching if not writing it down!
- logef=0;
- }
-
-
- ParamText(check_only?"\pinfected":"\prepaired",nil,nil,nil);
- logo=GetNewDialog(256,nil,(WindowPtr)-1);
- SetPort(logo);
-
- GetDialogItem(logo,2,nil,&volnh,nil);
- GetDialogItem(logo,3,nil,&dirnh,nil);
- GetDialogItem(logo,4,nil,&filnh,nil);
- GetDialogItem(logo,5,nil,&numh,nil);
- GetDialogItem(logo,6,nil,&toth,nil);
-
- ShowWindow(logo);
- DrawDialog(logo);
-
- for(queze=(VCB*)(GetVCBQHdr()->qHead);queze;queze=(VCB*)queze->qLink)
- {
- // Don't bother if it's software or hardware locked
- if((queze->vcbAtrb&0x8000) || (queze->vcbAtrb&0x0080)) continue;
-
- BlockMoveData(queze->vcbVN,volnm,28);
- SetDialogItemText(volnh,volnm);
- SetDialogItemText(dirnh,"\p<root>");
-
- RecurseDirectory(queze->vcbVRefNum,fsRtDirID);
-
- if(hit_but) break;
- }
-
- if(logef)
- {
- WriteString(logef,"\pEnd of list\r");
- FSClose(logef);
- }
-
- NumToString(toto,tots); // numo will always be up-to-date
- SetDialogItemText(toth,tots);
-
- GetDialogItem(logo,7,nil,&toth,nil);
- SetDialogItemText(toth,hit_but?"\pCancelled - Click to quit":"\pCompleted - Click to quit");
-
- FlushEvents(everyEvent,0);
- ValidRect(&logo->portRect);
- for(;;)
- {
- EventRecord ev;
-
- WaitNextEvent(everyEvent,&ev,60,nil);
- if(ev.what==updateEvt) LogoUpdate();
- {
- }
- if(ev.what==keyDown || ev.what==mouseDown) break;
- }
- }
- }
-
- void LogoUpdate(void)
- {
- SetPort(logo);
- BeginUpdate(logo);
- DrawDialog(logo);
- EndUpdate(logo);
- }
-
- void RecurseDirectory(short vref, long did)
- {
- HFileInfo tpb;
- FSSpec tana;
- short idx, rrf, i;
-
- if(Button() || hit_but) {hit_but=1; return;}
-
- lantana=&tana;
-
- tana.vRefNum=vref;
- tana.parID=did;
-
- tpb.ioCompletion=nil;
- tpb.ioNamePtr=tana.name;
- tpb.ioVRefNum=tana.vRefNum;
- for(idx=1;;idx++)
- {
- tpb.ioFDirIndex=idx;
- tpb.ioDirID=tana.parID;
-
- PBGetCatInfoSync((CInfoPBRec*)&tpb);
- if(tpb.ioResult) break;
-
- if(tpb.ioFlAttrib&ioDirMask)
- {
- if(!(upi&0xF))
- {
- EventRecord ev;
-
- SetDialogItemText(dirnh,tana.name);
- GetNextEvent(everyEvent,&ev);
- if(ev.what==updateEvt) LogoUpdate();
- // other events are ignored
- }
- upi++;
-
- RecurseDirectory(vref,tpb.ioDirID);
- lantana=&tana;
- continue;
- }
- /* If the resource fork is already open it's probably us - and even
- if it isn't we should be fiddling with running applications */
- if(tpb.ioFlAttrib&0x04) continue;
-
- for(i=0;i<ntt;i++) if(tpb.ioFlFndrInfo.fdType==targType[i]) break;
- if(i<ntt)
- {
- char saveco, reso;
-
- saveco=check_only;
-
- rrf=FSpOpenResFile(&tana,fsRdWrPerm);
- if(!rrf || rrf==-1)
- {
- rrf=FSpOpenResFile(&tana,fsRdPerm);
- if(!rrf || rrf==-1) continue;
- // file is locked
- check_only=1;
- }
-
- reso=RepairApp(rrf);
- CloseResFile(rrf);
-
- if(reso)
- {
- if(!saveco && check_only)
- {
- ParamText(tana.name,nil,nil,nil);
- Alert(132,nil);
- if(logef) WriteString(logef,
- "\p• Following app is infected but was not repaired: ");
- }
- SetDialogItemText(filnh,tana.name);
- ufi=0;
- numo++;
-
- // If ParamText was called for another alert it could stuff us up here
- SetPort(logo);
- ParamText(saveco?"\pinfected":"\prepaired",nil,nil,nil);
- DrawDialog(logo);
-
- if(logef) WriteAppPath();
- }
- toto++;
- check_only=saveco;
-
- SetPort(logo);
-
- if(!(ufi&0xF))
- {
- NumToString(numo,nums);
- SetDialogItemText(numh,nums);
- NumToString(toto,tots);
- SetDialogItemText(toth,tots);
- }
- ufi++;
- }
- }
- }
-
-
-
- /* Writes lantana's path to logef */
- void WriteAppPath(void)
- {
- HFileInfo tpb;
- Str63 dina;
- long *bsp;
-
-
- tpb.ioCompletion=nil;
- tpb.ioVRefNum=lantana->vRefNum;
- tpb.ioNamePtr=dina;
- tpb.ioFDirIndex=-1;
-
- bsp=(long*)bigstak; // 8000-deep folders? no problem :-)
- *bsp=lantana->parID;
-
- while(*bsp!=fsRtDirID)
- {
- tpb.ioDirID=*bsp;
- PBGetCatInfoSync((CInfoPBRec*)&tpb);
- if(tpb.ioResult) break;
- *(++bsp)=tpb.ioFlParID;
- }
-
- // It's too late tonight to figure out how to construct the pathname
- // backwards in the buffer. And this bit doesn't need to be fast.
-
- WriteString(logef,volnm);
- WriteString(logef,"\p:");
- for(bsp--;bsp>=(long*)bigstak;bsp--)
- {
- tpb.ioDirID=*bsp;
- PBGetCatInfoSync((CInfoPBRec*)&tpb);
-
- WriteString(logef,dina);
- WriteString(logef,"\p:");
- }
- WriteString(logef,lantana->name);
- WriteString(logef,"\p\r");
- }
-
-
- /* Yes, I know, I should've made it a dialog or put in more buttons or something */
- pascal Boolean AlertKludge(DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
- {
- ControlHandle abh, bbh;
- KeyMap kk;
- Boolean tobecheck;
-
- GetKeys(kk);
- tobecheck = (kk[1]&0x8000)?1:0;
-
- if(theEvent->what==keyDown && (theEvent->message&charCodeMask)==13)
- {
- GetDialogItem(theDialog,1,nil,(Handle*)&abh,nil);
- HiliteControl(abh,1);
- Delay(8,nil);
- HiliteControl(abh,0);
-
- *itemHit=1;
- return true;
- }
-
- if(theEvent->what==mouseDown) lmdco=check_only;
-
- if(tobecheck==check_only) return false;
-
- GetDialogItem(theDialog,2,nil,(Handle*)&abh,nil);
- GetDialogItem(theDialog,3,nil,(Handle*)&bbh,nil);
-
- if(check_only=tobecheck) // intentional single equal-sign!
- {
- SetControlTitle(abh,"\pExamine One App…");
- SetControlTitle(bbh,"\pExamine All Volumes");
- }
- else
- {
- SetControlTitle(abh,"\pRepair One App…");
- SetControlTitle(bbh,"\pRepair All Volumes");
- }
-
- if(theEvent->what==mouseDown) lmdco=check_only;
-
- return false;
- }
-
-
-
- void DecodeVirus(void)
- {
- StandardFileReply rep;
- Handle org, dst;
- short rrf, i;
-
- StandardGetFile(nil,-1,nil,&rep);
- if(!rep.sfGood) ExitToShell();
-
- rrf=FSpOpenResFile(&rep.sfFile,fsRdWrPerm);
- org=Get1Resource('INIT',33);
- HLock(org);
- dst=NewHandle(GetHandleSize(org));
- HLock(dst);
-
- BlockMoveData(*org,*dst,GetHandleSize(org));
-
- for(i=0x0A;i<0x6EE+0x0A;i++) (*dst)[i]^=0xCC;
-
- HUnlock(dst);
- HUnlock(org);
-
- AddResource(dst,'INIT',0,nil);
-
- CloseResFile(rrf);
- }